package cn.itcast.redisdemo.config;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置
 */
@Configuration
public class ThreadPoolConfig {

    private static  final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNamePrefix("my-thread-").build();
    @Bean
    public ThreadPoolExecutor the(){
        return new ThreadPoolExecutor(
                2, 2, 10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100),
                threadFactory,
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
